package dataDraw;

import data.Position;
import tools.*;

import java.awt.*;
import java.awt.Point;

/**
 * User: Szymon Kudzia
 * Date: 22.04.13
 * Time: 16:14
 * @Pattern: Decorator
 */
public class TextDraw {
	protected Graphics g;

	public void setGraphics(Graphics g) {
		this.g = g;
	}

	public void drawString(String msg, Position current) {

		FontMetrics fontMetrics = g.getFontMetrics();
		g.drawString(msg, current.getX() + Constants.MARGIN, current.getY() + fontMetrics.getHeight());
	}

	public void drawString(String msg, Position position, boolean bold, boolean italic) {
		drawString(msg, position, bold, italic, "", Integer.MIN_VALUE);
	}

	public void drawString(String msg, Position position, boolean bold, boolean italic, String fontFamily) {
		drawString(msg, position, bold, italic, fontFamily, Integer.MIN_VALUE);
	}

	public void drawString(String msg, Position position, boolean bold, boolean italic, int fontSize) {
		drawString(msg, position, bold, italic, "", fontSize);
	}

	public void drawString(String msg, Position position, String fontFamily) {
		drawString(msg, position, fontFamily, Integer.MIN_VALUE);
	}

	public void drawString(String msg, Position position, int fontSize) {
		drawString(msg, position, "", fontSize);
	}

	public void drawString(String msg, Position position, String fontFamily, int fontSize) {
		drawString(msg, position, g.getFont().isBold(), g.getFont().isItalic(), fontFamily, fontSize);
	}

	public void drawString(String msg, Position position, boolean bold, boolean italic, String fontFamily, int fontSize) {
		Font oldFont = g.getFont();

		setFontStyle(bold, italic, fontFamily, fontSize);
		drawString(msg, position);

		g.setFont(oldFont);
	}

//	protected tools.Point getStringSize(String msg) {
//		FontMetrics fontMetrics = g.getFontMetrics();
//		return new tools.Point(fontMetrics.stringWidth(msg) + 2 * Constants.MARGIN, fontMetrics.getHeight());
//	}

//	protected void drawString(String msg, tools.Point p) {
//		setFontStyle();
//
//		FontMetrics fontMetrics = g.getFontMetrics();
//		g.drawString(msg, p.x + Constants.MARGIN, p.y + fontMetrics.getHeight());
//	}


	protected void setFontStyle(boolean bold, boolean italic, String fontFamily, int fontSize)
	{
		int fontStyle = Font.PLAIN;
		String family = fontFamily;
		int size = fontSize;

		if (bold)
			fontStyle = Font.BOLD;

		if (italic)
			fontStyle |= Font.ITALIC;

		if (fontFamily.equals(""))
			family = g.getFont().getFamily();

		if (fontSize < 0) {
			size = g.getFont().getSize();
		}

		Font f = new Font(family, fontStyle, size);
		g.setFont(f);
	}
}
